/*
 * @Description: 字符串转换对象
 * @Author: zzj
 * @Date: 2021-09-10 14:13:59
 * @LastEditors: zzj
 * @LastEditTime: 2021-09-14 21:22:20
 */

/*
var url = 'http://www.briup.com/?user=anonymous&id=123&age=45&city=Wenzhou
结果：
{ 
  url:’ http://www.briup.com’
user: 'anonymous',
  id: 123,
  age:45  
  city: 'wenzhou', 
}
 */

var url = "http://www.briup.com/?user=anonymous&id=123&age=45&city=Wenzhou";
const paramsStr = /.+\?(.+)$/.exec(url)[1]; // 将 ? 后面的字符串取出来
const paramsArr = paramsStr.split('&'); // 将字符串以 & 分割后存到数组中
let paramsObj = {};
// 将 params 存到对象中
paramsArr.forEach(param => {
	let [key, val] = param.split('='); // 分割 key 和 value
	paramsObj[key] = val;
})
console.log(paramsObj);